package com.ruix.app.ui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.ruix.app.R;
import com.ruix.app.util.GlideUitl;
import com.ruix.app.util.LogUitl;

import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * Created by hadexs on 2017/5/14.
 */

public class LessonPicViewAdapter extends PagerAdapter{


    private Context context;
    private ArrayList<String> picAddress;
    private ArrayList<ImageView> views;


    public LessonPicViewAdapter(Context context) {
        this.context = context;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
//        final Context context = container.getContext();
        View itemView = LayoutInflater.from(context)
                .inflate(R.layout.layout_lesson_pic_view, container, false);
        final ImageView imageView = (ImageView) itemView.findViewById(R.id.iv_lesson_pic);
        GlideUitl.showImageView(picAddress.get(position),imageView);
        container.addView(imageView);
        return imageView;

//        return super.instantiateItem(container, position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }

    @Override
    public int getCount() {
        if (picAddress != null){
           return picAddress.size();
        }
        return 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    public void setPicAddress(ArrayList<String> picAddress) {
        this.picAddress = picAddress;
        notifyDataSetChanged();
    }
}
